﻿using System;
using System.Collections.Generic;

namespace DotNet.Phone8.MvvmLight.Extensions
{
    public class NavigationUri : Uri
    {
        private Dictionary<object, object> parameters;

        /// <summary>
        /// 在Phone8中的uri字符串必须以 斜线“/”开头，如“/mainpage.xaml”
        /// </summary>
        /// <param name="uri">页面的相对路径</param>
        /// <param name="uriKind">跳转的uri类型</param>
        public NavigationUri(string uri, UriKind uriKind = UriKind.Relative)
            : base(uri, uriKind)
        {
            parameters = new Dictionary<object, object>();
        }

        public void AddParameter<TParaKey, TParaValue>(TParaKey key, TParaValue value)
        {
            if (!parameters.ContainsKey(key))
            {
                parameters.Add(key, value);
            }
        }

        public TParaValue GetParamater<TParaKey, TParaValue>(TParaKey key)
        {
            TParaValue value = default(TParaValue);
            if (parameters.ContainsKey(key) && parameters[key] is TParaValue)
            {
                value = (TParaValue)parameters[key];
            }
            return value;
        }

        public bool ContainsParameter<TParaKey>(TParaKey key)
        {
            return parameters.ContainsKey(key);
        }

        public Dictionary<object, object> GetAllParameters()
        {
            return parameters;
        }
    }
}
